package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketGoods;
import com.cskaoyan.market.service.WxGoodsService_YYH;
import com.cskaoyan.market.util.ResponseUtil;
import org.apache.shiro.mgt.SecurityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: 鲸落
 * @Date: 2024/05/21/20:33
 * @Version: 1.0
 * @Description:
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController_YYH {
    @Autowired
    SecurityManager securityManager;
    @Autowired
    WxGoodsService_YYH goodsService;
    @GetMapping("related")  // 商品详情页底部，推荐相关商品  功能正常
    public Object related(Integer id){
        MarketGoods goods = goodsService.selectGoodsById(id);
        if (goods == null) {
            return ResponseUtil.badArgumentValue();
        }
        // 当前商品所属类目Id
        Integer categoryId = goods.getCategoryId();
        // 推荐同类目的其他商品，最多查找六个相关商品
        Integer relatedGoodsNum = 6;
        List<MarketGoods> goodsList = goodsService.selectGoodsByCategory(categoryId, relatedGoodsNum);
        return ResponseUtil.okList(goodsList);
    }
    @GetMapping("detail")   // 商品详情页 功能正常
    public Object detail(Integer id){
        // 此id为goodsId
        Map<String,Object> data= goodsService.detail(id);
        return ResponseUtil.ok(data);
    }
}
